<template>
  <!-- 2.准备一个具备宽高的容器 -->
  <div class="BarChart-container" ref="chartRef"></div>
</template>

<script lang="ts">
export default {
  name: "BarChart",
};
</script>

<script lang="ts" setup>
// 1.引入echarts
import * as echarts from "echarts";
import { onMounted, ref } from "vue";

const chartRef = ref();
onMounted(() => {
  // 3.初始化echarts实例
  const myEcharts = echarts.init(chartRef.value);
  // 4.定义图标选项
  const option = {
    xAxis: {
      data: [
        "00:00",
        "01:00",
        "02:00",
        "03:00",
        "04:00",
        "05:00",
        "06:00",
        "07:00",
        "08:00",
        "09:00",
        "10:00",
        "11:00",
        "12:00",
        "13:00",
      ],
    },
    yAxis: {
      show: false, //y轴隐藏
    },
    tooltip: {
      trigger: "axis",
    },
    series: {
      name: "实时交易量",
      type: "bar",
      data: [22, 15, 33, 25, 36, 29, 32, 23, 35, 29, 18, 26, 36, 29],
      itemStyle: { color: "#3398db" },
    },
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
    },
  };
  // 5.渲染图标
  myEcharts.setOption(option);
});
</script>

<style scoped>
.BarChart-container {
  height: 100%;
}
</style>
